<?php
	//No direct access
	defined('_JEXEC') or die('Restricted access');
?>
<div id="ownservices">
	<div id="mainmenuownservice"><?php echo MenuHelper::nav(); ?></div>
		<div id="mainownservice">
			<h3><?php echo JText::_('OWNSERVICE_CUSTOMER_TRANSFERS'); ?></h3>
			<hr />
			<script language="javascript" type="text/javascript">
				<!--
					function submitbutton(pressbutton)
					{
						var form = document.adminForm;

						if (form.boxchecked.value == 0){
							alert( "<?php echo JText::_( 'OWNSERVICE_SELECT_CUSTOMER_TRANSFERS', true ); ?>" );
						} else {
							submitform( pressbutton );
						}
					}
				//-->
			</script>
			<div id="toolbar">
				<a class="toolbar" onclick="javascript: submitbutton('customerapprove')" href="#">
					<span title="<?php echo JText::_('OWNSERVICE_SUBMIT'); ?>" class="icon-32-new"></span>
					<?php echo JText::_('OWNSERVICE_SUBMIT'); ?>
				</a>
				<a class="toolbar" onclick="javascript: submitbutton('customeredit')" href="#">
					<span title="<?php echo JText::_('OWNSERVICE_EDIT'); ?>" class="icon-32-edit"></span>
					<?php echo JText::_('OWNSERVICE_EDIT'); ?>
				</a>
				<a class="toolbar" onclick="javascript: submitbutton('customerdelete')" href="#">
					<span title="<?php echo JText::_('OWNSERVICE_DELETE'); ?>" class="icon-32-delete"></span>
					<?php echo JText::_('OWNSERVICE_DELETE'); ?>
				</a>
			</div>
			<div class="clear"> </div>
			<form action="<?php echo JRoute::_('index.php?option=com_ownservice'); ?>" method="post" name="adminForm" autocomplete="off">
				<table>
					<tr>
						<td width="100%">
							<?php echo JText::_( 'OWNSERVICE_FILTER' ); ?>:<input type="text" name="search" value="<?php echo htmlspecialchars($this->lists['search']);?>"  onchange="document.adminForm.submit();" />
							<button onclick="this.form.submit();" class="button">
								<?php echo JText::_( 'Go' ); ?>
							</button>
							<button onclick="document.adminForm.search.value='';this.form.submit();" class="button">
								<?php echo JText::_( 'Reset' ); ?>
							</button>
						</td>
						<td nowrap="nowrap">
							<?php if( isset($this->lists['branch']) ): ?>
									<?php echo $this->lists['branch']; ?>
							<?php endif; ?>
						</td>
					</tr>
				</table>
				<table class="adminlist" cellspacing="1">
					<tr>
						<td align="center" class="tablelist">
							<input type="checkbox" name="toggle" value="" onclick="checkAll(<?php echo count($this->rows); ?>);" />
						</td>
						<td align="center" class="tablelist">
							<?php echo JText::_('OWNSERVICE_ACCOUNT_NO'); ?>
						</td>
						<td align="center" class="tablelist">
							<?php echo JHTML::_('grid.sort', 'OWNSERVICE_ACCOUNT_NAME', 'a.account_name', $this->lists['order_Dir'], $this->lists['order'] ); ?>
						</td>
						<td align="center" class="tablelist">
							<?php echo JHTML::_('grid.sort',  'OWNSERVICE_USER', 'u.name', $this->lists['order_Dir'], $this->lists['order'] ); ?>
						</td>
						<td align="center" class="tablelist">
							<?php echo JHTML::_('grid.sort', 'OWNSERVICE_BANK_NAME', 'a.bank_name', $this->lists['order_Dir'], $this->lists['order'] ); ?>
						</td>
						<td align="center" class="tablelist">
							<?php echo JHTML::_('grid.sort', 'OWNSERVICE_BRANCH_NAME', 'a.branch_name', $this->lists['order_Dir'], $this->lists['order'] ); ?>
						</td>
						<td align="center" class="tablelist">
							<?php echo JHTML::_('grid.sort',  'OWNSERVICE_CREATE_DATE', 't.created', $this->lists['order_Dir'], $this->lists['order'] ); ?>
						</td>
						<td align="center" class="tablelist">
							<?php echo JHTML::_('grid.sort',  'OWNSERVICE_AMOUNT_TRANSFER', 't.amount', $this->lists['order_Dir'], $this->lists['order'] ); ?>
							<br />AUD
						</td>
						<td align="center" class="tablelist">
							<?php echo JHTML::_('grid.sort',  'OWNSERVICE_RATE', 't.rate', $this->lists['order_Dir'], $this->lists['order'] ); ?>
						</td>
						<td align="center" class="tablelist">
							<?php echo JHTML::_('grid.sort',  'OWNSERVICE_TOTAL_EXCHANGE', 't.total', $this->lists['order_Dir'], $this->lists['order'] ); ?>
						</td>
					</tr>
					<tfoot>
						<tr>
						  <td colspan="9"><?php echo $this->pageNav->getListFooter(true); ?></td>
						</tr>
					</tfoot>
					<tbody>
						<?php
							$k 			 	= 0;
							$total		 	= 0;
							$sum_amount		= 0;
							$sum_rate	 	= 0;
							$sum_total		= 0;
							$priceformat 	= OwnserviceHelper::getParams('price_format', '#,###.##');
							$dateformat  	= OwnserviceHelper::getParams('date_format', '%d/%m/%Y'); 

							for($i=0,$n=count($this->rows);$i<$n;$i++):
								$row		= $this->rows[$i];
								$checked	= JHTML::_('grid.checkedout', $row, $i );
								$link_member= JRoute::_('index.php?option=com_ownservice&controller=member&task=detail&id='.$row->memberid);
						?>
						<tr class="<?php echo "row$k"; ?>">
							<td align="center" class="inner_tablelist"><?php echo $checked; ?></td>
							<td align="center" class="inner_tablelist">
								<?php echo OwnserviceHelper::accountFormat($row->account); ?>
							</td>
							<td class="inner_tablelist">
								<?php echo $row->account_name; ?>
							</td>
							<td class="inner_tablelist">
								<a href="<?php echo $link_member; ?>">
									<?php echo $row->username; ?>
								</a>
							</td>
							<td class="inner_tablelist">
								<?php if(strtolower($row->bank_name)=='other'): ?>
									<?php echo $row->bank_other; ?>
								<?php else: ?>
									<?php echo $row->bank_name; ?>
								<?php endif; ?>
							</td>
							<td class="inner_tablelist"> 
								<?php echo $row->branch_name; ?>	
							</td>
							<td class="inner_tablelist" align="center">
								<?php echo JHTML::_('date', $row->created, $dateformat); ?>
							</td>
							<td class="inner_tablelist" align="right" nowrap="nowrap">
								<?php echo OwnserviceHelper::moneyFormat($priceformat,$row->amount); ?>
							</td>
							<td class="inner_tablelist" align="right" nowrap="nowrap">
								<?php
									$color = '';
									if($row->extrarate > 0.00 ) {
										$color = 'red';
									} else if($row->extrarate < 0.00) {
										$color = 'green';
									}
								?>
								<?php if(!$row->iscore): ?>
									<div style="border-bottom: 1px dotted #ccc;">
										<?php echo OwnserviceHelper::moneyFormat($priceformat,$row->rate_th); ?> THB
									</div>
								<?php endif; ?>
								<div class ="<?php echo $color; ?>">
									<?php echo OwnserviceHelper::moneyFormat($priceformat,$row->rate+$row->extrarate).' '.$row->rate_code; ?> 
								</div>
							</td>
							<td class="inner_tablelist" align="right" nowrap="nowrap">
								<?php if(!$row->iscore): ?>
									<div style="border-bottom: 1px dotted #ccc;">
										<?php echo OwnserviceHelper::moneyFormat($priceformat,$row->total_th); ?> THB
									</div>
								<?php
									else:
										if($row->extratotal > 0.00 ){
											$sum_total = $sum_total + $row->extratotal;	
										} else {
											$sum_total = $sum_total + ( ($row->amount * ($row->rate+$row->extrarate)) - ($row->bankfee+$row->extrabfee));  
										}
									endif; 
								?>
								<div class="<?php echo ($row->extratotal > 0.00?'red':''); ?>">
									<?php
										if($row->extratotal > 0.00) {
											echo OwnserviceHelper::moneyFormat($priceformat, $row->extratotal).' '.$row->rate_code;
										} else {
											echo OwnserviceHelper::moneyFormat($priceformat,( ($row->amount * ($row->rate+$row->extrarate)) - ($row->bankfee+$row->extrabfee))).' '.$row->rate_code;
										}
									?>
								</div> 
							</td>
						</tr>
						<?php $k = 1 - $k; endfor; ?>
				</table>

				<div>
					<input type="hidden" name="boxchecked" value="0" />
					<input type="hidden" name="id" value="" />
					<input type="hidden" name="option" value="com_ownservice" />
					<input type="hidden" name="view" value="transactions" />
					<input type="hidden" name="task" value="customertransfers" />
					<input type="hidden" name="controller" value="transaction" />
					<input type="hidden" name="filter_order" value="<?php echo $this->lists['order']; ?>" />
					<input type="hidden" name="filter_order_Dir" value="<?php echo $this->lists['order_Dir']; ?>" />
					<input type="hidden" name="Itemid" value="<?php echo JRequest::getVar('Itemid'); ?>" />
					<?php echo JHTML::_( 'form.token' ); ?>
				</div>

			</form>
		</div>
</div>